package com.qeado.site.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.qeado.admin.common.BaseConstData;
import com.qeado.common.helper.AttributeHelper;
import com.qeado.site.model.FilterWord;
import com.qeado.site.service.FilterWordManageService;

@Controller
public class FilterWordManageController {

	@Autowired
	private FilterWordManageService filterWordManageService;
	
	@RequestMapping("/filterWordsManage.ac")
	public ModelAndView searchFilterWord(HttpServletRequest request, FilterWord filterWord){
		AttributeHelper.removeSessionAttribute(request, "T_");
		List<FilterWord> filterWordList = this.filterWordManageService.getFilterWordByWord(filterWord);
		return new ModelAndView("site/filter_words_manage","filterWordList",filterWordList);
	}
	
	@RequestMapping("/filterWordSave.ac")
	public String saveNewFilterWord(HttpServletRequest request, FilterWord filterWord){
		//insert and search
		filterWord.setCreator(request.getSession().getAttribute(BaseConstData.USER_ID).toString());
		String message = this.filterWordManageService.insertNewFilterWord(filterWord);
		List<FilterWord> filterWordList = this.filterWordManageService.getFilterWordByWord(null);
		request.setAttribute("message", message);
		request.setAttribute("filterWordList", filterWordList);
		return "site/filter_words_manage";
		
	}
	@RequestMapping("/deleteFilterWord.ac")
	public ModelAndView deleteFilterWordByWord(FilterWord filterWord){
		this.filterWordManageService.deleteFilterWordByWord(filterWord);
		List<FilterWord> filterWordList = this.filterWordManageService.getFilterWordByWord(null);
		return new ModelAndView("site/filter_words_manage","filterWordList",filterWordList);
	}
	
}
